const sharp=/*wgsl*/`
struct SharpData{
  sharpFactor: f32,
  sharpPreBlurFactor: f32,
}
@group(0) @binding(0) var<uniform> taaData: SharpData;
@group(0) @binding(1) var inTex : texture_2d<f32>;
@group(0) @binding(2) var outTex : texture_storage_2d<rgba16float, write>;

var<private> texSize: vec2<u32>;
var<private> fragCoord: vec2<i32>;

@compute @workgroup_size( 8 , 8 , 1 )
fn main( @builtin(workgroup_id) workgroup_id : vec3<u32> , @builtin(global_invocation_id) globalInvocation_id : vec3<u32>)
{
  fragCoord = vec2<i32>( globalInvocation_id.xy );
  texSize = textureDimensions(outTex).xy;
  if(fragCoord.x >= i32(texSize.x) || fragCoord.y >= i32(texSize.y)){
      return;
  }
  
  let c0 = textureLoad(inTex, vec2<i32>(fragCoord.x, fragCoord.y - 1), 0);
  let c1 = textureLoad(inTex, vec2<i32>(fragCoord.x, fragCoord.y + 1), 0);
  let gradientVertical = c0 - c1;

  let c2 = textureLoad(inTex, vec2<i32>(fragCoord.x - 1, fragCoord.y), 0);
  let c3 = textureLoad(inTex, vec2<i32>(fragCoord.x + 1, fragCoord.y), 0);
  var gradientHorizontal = c3 - c2;
  var gradient = sqrt(gradientHorizontal * gradientHorizontal + gradientVertical * gradientVertical);
  var roundColor = (c0 + c1 + c2 + c3) * 0.25;
  let originColor = textureLoad(inTex, fragCoord, 0);
  // 第一种实现方案
  // var sharpenedColor = originColor + taaData.sharpFactor * gradient;
  // sharpenedColor=clamp(sharpenedColor, vec4<f32>(0.0), sharpenedColor);
  // textureStore(outTex, fragCoord , sharpenedColor);
  // 第二种实现方案
  let blurColor = mix(roundColor, originColor, taaData.sharpPreBlurFactor);
  var oc = (originColor - blurColor * taaData.sharpFactor) / (1.0 - taaData.sharpFactor);
  oc = clamp(oc, vec4<f32>(0.0), oc);
  textureStore(outTex, fragCoord , oc);
}
`
export {sharp}